package top.luckyluxcis.api;

import lombok.experimental.UtilityClass;
import top.luckyluxcis.RollApi;
import top.luckyluxcis.type.News;
import top.luckyluxcis.util.MapUtil;

import java.util.List;
import java.util.Map;

/**
 * @author Zhuang
 * @since 2023/9/25
 */
@SuppressWarnings("unused")
@UtilityClass
public class NewsUtil {
    private static final RollApi API = RollApi.getInstance();

    /**
     * 获取所有新闻类型列表
     *
     * @return {@link List}<{@link News.Type}>
     */
    public static List<News.Type> types() {
        return API.get("/news/types/v2", MapUtil.empty(), List.class, News.Type.class);
    }

    /**
     * 获取指定新闻类型的新闻列表。
     *
     * @param typeId 类型id，从上面的新闻类型列表中获取
     * @param page   当前页数
     * @return {@link List}<{@link News}>
     */
    public static List<News> list(String typeId, int page) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("typeId", typeId)
                .put("page", page)
                .build();
        return API.get("/news/list/v2", params, List.class, News.class);
    }

    /**
     * 根据新闻id获取新闻详情。
     *
     * @param newsId 消息id
     * @return {@link List}<{@link News.Detail}>
     */
    public static List<News.Detail> detail(String newsId) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("newsId", newsId)
                .build();
        return ((News) API.get("/news/details/v2", params, News.class)).getItems();
    }
}
